using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace OBalanc
{
    public class Notif : Form
    {
        #region Standart

        private IContainer components;
        private Label lblDisplayText;
        private Label OBalance;
        private Timer SlideDown;
        private Timer SlideUp;
        private Timer timerShow;
        private string DisplayText;

        public Notif()
        {
            InitializeComponent();
        }

        public Notif(string displayText)
        {
            DisplayText = displayText;
            InitializeComponent();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }
        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Notif));
            this.lblDisplayText = new System.Windows.Forms.Label();
            this.OBalance = new System.Windows.Forms.Label();
            this.timerShow = new System.Windows.Forms.Timer(this.components);
            this.SlideUp = new System.Windows.Forms.Timer(this.components);
            this.SlideDown = new System.Windows.Forms.Timer(this.components);
            this.SuspendLayout();
            // 
            // lblDisplayText
            // 
            this.lblDisplayText.BackColor = System.Drawing.Color.Transparent;
            this.lblDisplayText.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
            this.lblDisplayText.ForeColor = System.Drawing.Color.LightSkyBlue;
            this.lblDisplayText.Location = new System.Drawing.Point(8, 16);
            this.lblDisplayText.Name = "lblDisplayText";
            this.lblDisplayText.Size = new System.Drawing.Size(232, 23);
            this.lblDisplayText.TabIndex = 0;
            this.lblDisplayText.Text = "lblDisplayText";
            this.lblDisplayText.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.lblDisplayText.Click += new System.EventHandler(this.Notif_Click);
            // 
            // OBalance
            // 
            this.OBalance.BackColor = System.Drawing.Color.Transparent;
            this.OBalance.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
            this.OBalance.ForeColor = System.Drawing.Color.DodgerBlue;
            this.OBalance.Location = new System.Drawing.Point(8, 0);
            this.OBalance.Name = "OBalance";
            this.OBalance.Size = new System.Drawing.Size(72, 16);
            this.OBalance.TabIndex = 1;
            this.OBalance.Text = "OBalance";
            this.OBalance.Click += new System.EventHandler(this.Notif_Click);
            // 
            // timerShow
            // 
            this.timerShow.Interval = 10000;
            this.timerShow.Tick += new System.EventHandler(this.timerShow_Tick);
            // 
            // SlideUp
            // 
            this.SlideUp.Interval = 40;
            this.SlideUp.Tick += new System.EventHandler(this.SlideUp_Tick);
            // 
            // SlideDown
            // 
            this.SlideDown.Interval = 40;
            this.SlideDown.Tick += new System.EventHandler(this.SlideDown_Tick);
            // 
            // Notif
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.BackColor = System.Drawing.Color.Red;
            this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
            this.ClientSize = new System.Drawing.Size(250, 50);
            this.ControlBox = false;
            this.Controls.Add(this.OBalance);
            this.Controls.Add(this.lblDisplayText);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "Notif";
            this.ShowInTaskbar = false;
            this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
            this.Text = "Notif";
            this.TransparencyKey = System.Drawing.Color.Red;
            this.Click += new System.EventHandler(this.Notif_Click);
            this.ResumeLayout(false);

        }

        #endregion

        #endregion

        public void NotifShow(string displayText)
        {
            DisplayText = displayText;

            Size = new Size(Size.Width, 0);
            Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - Size.Width,
                            Screen.PrimaryScreen.WorkingArea.Height - Size.Height);
            lblDisplayText.Text = DisplayText;
            timerShow.Enabled = true;
            timerShow.Interval = 10000;
            timerShow.Start();
            SlideUp.Enabled = true;
            SlideUp.Interval = 40;
            SlideUp.Start();
            Visible = true;
            TopMost = MainWind.Property.NotifTopMost;

            if (MainWind.Property.ShowTraf && MainWind.Property.ShowMoney)
            {
                lblDisplayText.Font = new Font("Microsoft Sans Serif", 10, FontStyle.Bold);
            }
            else
            {
                lblDisplayText.Font = new Font("Microsoft Sans Serif", 12, FontStyle.Bold);
            }
        }

        private void timerShow_Tick(object sender, EventArgs e)
        {
            timerShow.Stop();
            SlideDown.Enabled = true;
            SlideDown.Interval = 40;
            SlideDown.Start();
        }

        private void Notif_Click(object sender, EventArgs e)
        {
            if (MainWind.Property.CloseClickNotif)
            {
                timerShow.Stop();
                SlideDown.Enabled = true;
                SlideDown.Interval = 40;
                SlideDown.Start();
            }
        }

        private void SlideUp_Tick(object sender, EventArgs e)
        {
            Visible = true;
            if (Size.Height < 50)
            {
                Size = new Size(Size.Width, Size.Height + 1);
                Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - Size.Width,
                            Screen.PrimaryScreen.WorkingArea.Height - Size.Height);
            }
            else
            {
                if (Size.Height == 50)
                {
                    SlideUp.Stop();
                }
            }
        }

        private void SlideDown_Tick(object sender, EventArgs e)
        {
            if (Size.Height > 2)
            {
                Size = new Size(Size.Width, Size.Height - 1);
                Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - Size.Width,
                            Screen.PrimaryScreen.WorkingArea.Height - Size.Height);
            }
            else
            {
                if (Size.Height == 2)
                {
                    timerShow.Stop();
                    SlideUp.Stop();
                    SlideDown.Stop();
                    var sz1 = new Size(Size.Width, 0);
                    Size = sz1;
                    Visible = false;
                }
            }
        }

        
    }
}